package main.回溯;

import java.util.ArrayList;
import java.util.List;

/**
 * @author tmh
 * @date 2024/9/8 15:29
 * @description
 */
public class T77组合 {
    List<List<Integer>> result = new ArrayList<>();

    public List<List<Integer>> combine(int n, int k) {
        backTracking(new ArrayList<>(), n, k, 1);
        return result;
    }

    public void backTracking(List<Integer> list, int n, int k, int beginIndex) {
        if (list.size() == k) {
            result.add(new ArrayList<>(list));
            return;
        }
        //这里的n是可以取得到的，所以 这里是小于等于n
        for (int i = beginIndex; i <= n; i++) {
            list.add(i);
            backTracking(list, n, k, i+1);
            list.remove(list.size() - 1);
        }
    }
}
